<?php

namespace App\Jobs;

use Exception;
use App\Services\WxUser\WxUserService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

/**
 * 微信用户刷新处理
 * @package App\Jobs
 */
class WxUserRefresh implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    /**
     * 任务可以尝试的最大次数
     * @var int
     */
    public $tries = 3;
    /**
     * 超时时间
     * @var int
     */
    public $timeout = 120;

    protected $appid;
    protected $openId;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($appid, $openId)
    {
        $this->appid = $appid;
        $this->openId = $openId;
    }

    /**
     * 定义任务超时时间
     * @return static
     */
    public function retryUntil()
    {
        return now()->addSeconds(5);
    }
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(WxUserService $wxUserService)
    {
        $wxUserService->getUserDataByOpenId($this->openId, true);
    }

    /**
     * 执行失败的任务
     */
    public function failed(Exception $exception)
    {

    }
}
